<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/2/27
  Time: 20:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>管理员管理模块</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui/layui.js" type="text/javascript"></script>
</head>
<body>
<form class="layui-form" id="addForm" style="display: none;padding: 15px 15px 5px 5px"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
    <div class="layui-form-item">
        <label class="layui-form-label">账号</label>
        <div class="layui-input-block">
            <input type="text" name="username" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="password" name="password" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
    <!-- 更多表单结构排版请移步文档左侧【页面元素-表单】一项阅览 -->
</form>
    <button class="layui-btn" id="add">添加</button>
    <table id="myTable"></table>
    <script>
        layui.use(['form','table','layer'],function () {
            var table = layui.table;
            var form = layui.form;
            var layer = layui.layer;
            var $ = layui.$;
            //渲染表格 展示所有管理员
            table.render({
                elem:'#myTable',
                url:'${pageContext.request.contextPath}/cmfzAdmin/show',
                page:true,
                limit:3,
                limits:[3,4,5],
                cols:[[
                    {field:'id',title:'ID编号',sort:true,width:120},
                    {field:'username',title:'账号',sort:true,width:120},
                    {field:'password',title:'密码',sort:true,width:200},
                    {field:'salt',title:'盐值',sort:true,width:120},
                ]]
            })
            //添加管理员操作
            $('#add').click(function () {
                layer.open({
                    type:1,
                    title:'添加页面',
                    area:'500px',
                    content:$('#addForm')
                })
            })
            form.on('submit(*)',function () {
                $.ajax({
                    url:'${pageContext.request.contextPath}/cmfzAdmin/add',
                    data:$('#addForm').serialize(),
                    success:function (result) {
                        if(result.flag){
                            layer.msg('添加成功');
                            layer.closeAll();
                            $('#addForm')[0].reset();
                            table.reload('myTable');
                        }else {
                            layer.msg('添加成功');
                        }
                    }
                })
                return false;
            })
        })
    </script>
</body>
</html>
